package com.lwj.liwanjia.view.activity.login;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lwj.liwanjia.MainActivity;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class GuideActivity extends BaseActivity {


    @BindView(R.id.vp)
    ViewPager vp;

    private List<View> list = new ArrayList<>();
    private ImageView guideIv;

    @Override
    protected void initView() {
        View view1 = LayoutInflater.from(this).inflate(R.layout.guide_layout, null);
        ImageView image1 = (ImageView) view1.findViewById(R.id.iv_guide);
        image1.setImageResource(R.mipmap.yindaoye_1);
        View view2 = LayoutInflater.from(this).inflate(R.layout.guide_layout, null);
        ImageView image2 = (ImageView) view2.findViewById(R.id.iv_guide);
        image2.setImageResource(R.mipmap.yindaoye_2);
        View view3 = LayoutInflater.from(this).inflate(R.layout.guide_layout, null);
        ImageView image3 = (ImageView) view3.findViewById(R.id.iv_guide);
        guideIv = (ImageView) view3.findViewById(R.id.guideIv);
        image3.setImageResource(R.mipmap.yindaoye_3);
        list.add(view1);
        list.add(view2);
        list.add(view3);
        vp.setAdapter(new GuideViewAdapter());
    }

    @Override
    protected void initData() {
        guideIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(GuideActivity.this, MainActivity.class));
                finish();
            }
        });
        vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position == 0) {
                    guideIv.setVisibility(View.GONE);
                } else if (position == 1) {
                    guideIv.setVisibility(View.GONE);
                } else if (position == 2) {
                    guideIv.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_lead;
    }

    public class GuideViewAdapter extends PagerAdapter {


        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {
            return arg0 == arg1;
        }

        @Override
        public void destroyItem(ViewGroup view, int position, Object object) {
            view.removeView(list.get(position));
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            container.addView(list.get(position));
            return list.get(position);
        }

    }
}
